////////////////////////////////////////////////////////////////////////////
//	CameCore.h & GameCore.cpp
//		Class that handles core behavior of the game, containing functions
//		to initialize, update, render and shutdown the game. Since there
//		should always be only one instance of this class, it's a singleton.
//		Most of its functions are called by WinMain.
//
//	Author:					Daniel Lima - March 2012
/////////////////////////////////////////////////////////////////////////////

#ifndef GAME_CORE_H_
#define GAME_CORE_H_

// Include the Windows API using Lean and Mean to exclude rarely
// used stuff from its headers
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>

#include "Input/InputListener.h"		// This class should handle input

// Forward declarations
class IGameState;				// GameCore has a GameState pointer

// GameCore class
// Inherits from InputListener so it can handle input from InputManager
class GameCore : public InputListener
{
	// Singleton's static instance
	static GameCore* sm_pInstance;

	// Window information
	HWND	m_hWnd;				// Handle to the Window itself
	int		m_nScreenWidth;		// Window width in pixels
	int		m_nScreenHeight;	// Window height in pixels
	bool	m_bFullScreen;		// Is the game in full screen mode?

	/////////////////////////////////////////////////////////////////////

	// Current game state
	IGameState* m_pCurrentState;

	// Constructor - Initialize all variables to default values
	GameCore(void);

	// For a proper singleton, the trilogy needs to be defined
	GameCore(const GameCore&) {}					// Copy Constructor
	GameCore& operator=(const GameCore&) {}			// Assignment Operator
	~GameCore(void) {}								// Destructor

	// Update the game based on the current state and calculate game time
	void Update(void);

	// Render the game based on the current state
	void Render(void);

	// TESTS
	enum EInputBinds { COMMAND_ATTACK = 1, COMMAND_WALK_LEFT, COMMAND_WALK_RIGHT };
	int nTestImg;



	/////////////////////////////////////////////////////////////////////
public:

	// Used to access the singleton's instance
	static GameCore* GetInstance(void);

	// Used to delete the singleton's instance
	static void DeleteInstance(void);

	// Initialize the game engines with the right window parameters
	bool Initialize(HWND hWnd, HINSTANCE hInstance, int nScreenWidth, int nScreenHeight, bool bIsWindowed);

	// Run the main game loop
	bool Main(void);

	// Function called every time an input message is sent by the InputManager
	void HandleInput(const InputMessage * const pInputMsg);

	// Shutdown the game engines
	void Shutdown(void);


	///// Accessors ////////////////////////////////////
	inline HWND GetWindowHandle	(void) const { return m_hWnd; }
	inline int	GetScreenWidth	(void) const { return m_nScreenWidth; }
	inline int	GetScreenHeight	(void) const { return m_nScreenHeight; }
	inline bool IsFullScreen	(void) const { return m_bFullScreen; }
	////////////////////////////////////////////////////
};

#endif